package demoMod.nanaki.cards.nanaki;

import basemod.BaseMod;
import com.megacrit.cardcrawl.actions.AbstractGameAction;
import com.megacrit.cardcrawl.actions.common.ApplyPowerAction;
import com.megacrit.cardcrawl.actions.common.DamageAction;
import com.megacrit.cardcrawl.cards.DamageInfo;
import com.megacrit.cardcrawl.characters.AbstractPlayer;
import com.megacrit.cardcrawl.core.AbstractCreature;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.localization.CardStrings;
import com.megacrit.cardcrawl.monsters.AbstractMonster;
import demoMod.nanaki.NanakiMod;
import demoMod.nanaki.interfaces.NoteApplyHook;
import demoMod.nanaki.powers.NotePower;
import demoMod.nanaki.utils.GetWaitAction;

public class Concerto extends AbstractNanakiCard implements NoteApplyHook {
    public static final String ID = NanakiMod.makeID("Concerto");

    private static final CardStrings cardStrings = CardCrawlGame.languagePack.getCardStrings(ID);
    public static final String NAME = cardStrings.NAME;
    public static final String DESCRIPTION = cardStrings.DESCRIPTION;
    public static final String IMG_PATH = "cards/Concerto";

    private static final CardType TYPE = CardType.ATTACK;
    private static final CardRarity RARITY = CardRarity.UNCOMMON;
    private static final CardTarget TARGET = CardTarget.ENEMY;

    private static final int COST = 0;

    public Concerto() {
        super(ID, NAME, NanakiMod.getResourcePath(IMG_PATH), COST, DESCRIPTION, TYPE, RARITY, TARGET);
        this.baseDamage = 5;
        this.baseMagicNumber = this.magicNumber = 2;
    }

    @Override
    public Runnable getUpgradeAction() {
        return () -> {
            upgradeDamage(2);
            upgradeMagicNumber(1);
        };
    }

    @Override
    public void use(AbstractPlayer p, AbstractMonster m) {
        addToBot(new DamageAction(m, new DamageInfo(p, this.damage, this.damageTypeForTurn), AbstractGameAction.AttackEffect.SLASH_DIAGONAL));
        addToBot(new ApplyPowerAction(m, p, new NotePower(m, this.magicNumber)));
    }

    @Override
    public int onApplyNote(AbstractCreature target, int amount) {
        addToBot(GetWaitAction.doAndWait(() -> {
            if (AbstractDungeon.player.drawPile.contains(this) && !(target instanceof AbstractPlayer)) {
                if (AbstractDungeon.player.hand.size() < BaseMod.MAX_HAND_SIZE) {
                    AbstractDungeon.player.hand.addToHand(this);
                    this.unhover();
                    this.setAngle(0.0F, true);
                    this.lighten(false);
                    this.drawScale = 0.12F;
                    this.targetDrawScale = 0.75F;
                    this.applyPowers();
                    AbstractDungeon.player.drawPile.removeCard(this);
                }
                AbstractDungeon.player.hand.refreshHandLayout();
                AbstractDungeon.player.hand.glowCheck();
            }
        }, 0.0F));
        return amount;
    }
}
